package org.example.testWebsocket.service.impl;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.example.common.constant.WsConstant;
import org.example.testWebsocket.entity.WsMsg;
import org.example.testWebsocket.service.WebSocketService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class WebSocketServiceImpl implements WebSocketService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void sendMsg(WsMsg wsMsg) {
        stringRedisTemplate.convertAndSend(WsConstant.CHANNEL, JSONUtil.toJsonStr(wsMsg));
    }
}
